<#ibizinclude>
../../@MACRO/LANG_FUN.ftl
</#ibizinclude>
<#ibizinclude>
../@MACRO/CONTROL/CONTROL_HEADER-BASE.vue.ftl
</#ibizinclude>

    /**
     * 显示处理提示
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop({ default: true }) public showBusyIndicator?: boolean;

    /**
     * 部件行为--load
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() public loadAction!: string;

    /**
     * 部件样式名
     *
     * @public
     * @type {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public ganttClass: string = "gantt";

     /**
     * 语言
     *
     * @public
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */  
    public locale: string = 'zh-CN';

     /**
     * 语言资源
     *
     * @public
     * @type {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */   
    public localeZH: any =  {
        weekdays: ['星期一','星期二','星期三','星期四','星期五','星期六','星期日'],
        months: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
        Now: "现在",
        "X-Scale": "时间颗粒度",
        "Display task list": "显示列表",
        "Before/After": "数据范围"
    }

    /**
     * 配置参数
     *
     * @public
     * @type {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public options: any = {
        isflex: true,
        maxRows: 1000,
        dataType: 'treegrid',
        title: {
            label: ""
        },
        header: {
            yScole: false,
            taskListWidth: false,
        },
        calendar: {
            hour: {
                display: false
            }
        },
        chart: {
            progress: {
                bar: false
            },
            expander: {
                display: true
            },
        },
        taskList: {
            expander: {
                straight: false
            },
            labelField: 'text',
            columns: [
                <#if ctrl.getPSDETreeColumns()??>
                <#list ctrl.getPSDETreeColumns() as column>
                {
                    label: '${column.getCaption()}',
                    value: '<#if column.getName() == "begin">start<#else>${column.getName()}</#if>',
                    render: (task: any) => {
                        <#if column.render??> 
                        ${column.render.code}
                        <#else>
                        return this.getColumnValue(task, '<#if column.getName() == "begin">start<#else>${column.getName()}</#if>')
                        </#if>
                    },
                    <#if column.getName() == "text">
                    expander: true,
                    </#if>
                    width: <#if column.getWidth() gt 0>${column.getWidth()}<#else>100</#if>,
                    <#if column.isHideDefault()>
                    hidden: true,
                    </#if>
                    <#if column.getHeaderPSSysCss()??>
                    headerCls: '${column.getHeaderPSSysCss().getCssName()}',
                    </#if>
                    <#if column.getCellPSSysCss()??>
                    cellCls: '${column.getCellPSSysCss().getCssName()}',
                    </#if>
                },
                </#list>
                </#if>
            ]
        }
    };

    /**
     * 样式
     *
     * @public
     * @type {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public dynamicStyle: any = {};

    /**
     * 日程事件集合
     *
     * @public
     * @type {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public tasks: any[] = [];

    /**
     * 监听语言变化
     *
     * @public
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Watch('$i18n.locale')
    public onLocaleChange(newval: any, val: any) {
        this.locale = newval;
    }

    /**
     * 获取列属性值
     *
     * @public
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public getColumnValue(task: any, field: string) {
        <#if ctrl.getPSDETreeNodes()??>
        <#list ctrl.getPSDETreeNodes() as node>
        if(Object.is(task.id.split(';')[0], '${srfjavastring(node.getNodeType())}')) {
            <#if node.getPSDETreeNodeDataItems()??>
            <#list node.getPSDETreeNodeDataItems() as dataItem>
            <#if dataItem.getFrontPSCodeList()??>
            <#assign codelist = dataItem.getFrontPSCodeList()/>
            if (Object.is(field, '${dataItem.name}')) {
                let codelist: any[] = this.$store.getters.getCodeList('${codelist.getCodeName()}');
                if(codelist) {
                    return this.getCodeListItem(codelist, task[field]);
                }
            }
            </#if>
            </#list>
            </#if>
            return task[field];
        }
        </#list>
        </#if>
    }

    /**
     * 获取代码项
     *
     * @public
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public getCodeListItem(codelist: any, val: any) {
        for(let i = 0; i < codelist.items.length; i++) {
            if(Object.is(codelist.items[i].value, val)) {
                return codelist.items[i].text;
            }
        }
        return codelist.emptytext;
    }

    /**
     * 获取部件参数
     *
     * @returns {any}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public getOptions() {
        if(Object.is(this.locale, 'zh-CN')) {
            return { locale: this.localeZH, ...this.options };
        }
        return this.options;
    }

    /**
     * 搜索获取日程事件
     *
     * @param {*} $event 日期信息
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public load(task: any = {}) {
        const params: any = {
            srfnodeid: task && task.id ? task.id : "#",
            srfnodefilter: ''
        };
        let tempViewParams:any = JSON.parse(JSON.stringify(this.viewparams));
        let curNode:any = {}; 
        this.$util.deepObjectMerge(curNode, task);
        let tempContext:any = this.computecurNodeContext(curNode);
        if(curNode && curNode.srfparentdename) {
            Object.assign(tempContext,{ srfparentdename: curNode.srfparentdename });
            Object.assign(tempViewParams,{ srfparentdename: curNode.srfparentdename });
        }
        if(curNode && curNode.srfparentkey) {
            Object.assign(tempContext,{ srfparentkey: curNode.srfparentkey });
            Object.assign(tempViewParams,{ srfparentkey: curNode.srfparentkey });
        }
        Object.assign(params,{viewparams:tempViewParams});
        this.service.getNodes(tempContext,params).then((response: any) => {
            if (!response || response.status !== 200) {
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.info });
                return;
            }
            this.tasks = [...this.tasks, ...response.data];
            response.data.forEach((item: any) => {
                if(!item.collapsed) {
                    this.load(item);
                }
            })
            this.$emit("load", this.tasks);
        }).catch((response: any) => {
            if (response && response.status === 401) {
                return;
            }
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.info });
        });
    }

    /**
     * 计算当前节点的上下文
     *
     * @param {*} curNode 当前节点
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public computecurNodeContext(curNode:any){
        let tempContext:any = {};
        if(curNode && curNode.data && curNode.data.srfappctx){
            tempContext = JSON.parse(JSON.stringify(curNode.data.srfappctx));
        }else{
            tempContext = JSON.parse(JSON.stringify(this.context));
        }
        return tempContext;
    }

    /**
     * 节点展开
     *
     * @param {*} task 当前节点
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public taskItemExpand(task: any) {
        if(!task.collapsed) {
            let index: number = this.tasks.findIndex((item: any) => Object.is(task.id, item.parentId));
            if(index < 0) {
                this.load(task);
            }
        }
    }

    /**
     * 刷新
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public refresh() {
        this.load();
    }



    /**
     * 选中的数据
     *
     * @returns {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public selections: any[] = [];

    /**
     * 获取多项数据
     *
     * @returns {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public getDatas(): any[] {
        return this.selections;
    }

    /**
     * 获取单项树
     *
     * @returns {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public getData(): any {
        return null;
    }
             
    /**
     * vue 生命周期
     *
     * @returns
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public created() {
        this.locale = this.$i18n.locale;
        this.load();
    }

    /**
     * 点击事件
     *
     * @returns
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public taskClick({event, data}: {event: any, data: any}) {
        const _this: any = this;
        let key: string = data.id.split(';')[0].toLowerCase();
        if(_this[key + '_opendata'] instanceof Function) {
            _this[key + '_opendata']([data]);
        }
    }

<#ibizinclude>
../@MACRO/CONTROL/CONTROL_BOTTOM-BASE.vue.ftl
</#ibizinclude>